﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Wpf_Examples.Views
{
    /// <summary>
    /// GaugeDemoWindow.xaml 的交互逻辑
    /// </summary>
    public partial class GaugeDemoWindow : Window
    {
        public GaugeDemoWindow()
        {
            InitializeComponent();

            gauge.GetRealValue = (value) => value * 100;

            //创建定时器
            CreateTimer();
        }

        private void CreateTimer()
        {
            #region 每秒定时器服务
            DispatcherTimer cpuTimer = new DispatcherTimer
            {
                Interval = new TimeSpan(0, 0, 0, 1, 0)
            };
            cpuTimer.Tick += DispatcherTimer_Tick;
            cpuTimer.Start();
            #endregion
        }

        private void DispatcherTimer_Tick(object sender, EventArgs e)
        {
            Random rnd = new Random();
            int val = rnd.Next(gauge.Min,gauge.Max);
            gauge.Value = val;
        }
    }
}
